package com.example.vueblog;

/**
 * @author yushunshun
 * @date 2022/7/28 22:47
 */
public class MaoPao {

    public static void main(String[] args) {
        int[] arr = {1,2,20,4,3,5,8,10};


        int temp = 0 ;
        //记录总共要比较多少次
        for (int i = 0; i < arr.length - 1; i++) {
            //相邻对比
            for (int i1 = 0; i1 < arr.length - 1 - i; i1++) {
                //如果左边大于右边
                if (arr[i1]>arr[i1+1]){
                    temp = arr[i1];
                    arr[i1] = arr[i1+1];
                    arr[i1+1] = temp;
                }
            }
        }

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
}
